package com.zl.learning.thread.thread_local;

/**
 * Created by zhaolei on 2017/5/16.
 */
public class Test {
    public static void main(String[] args) {
        new Thread(()->{
            while (true){
                ThreadLocal t = TestThreadLocal.getMt();
                Object o = t.get();
                TestThreadLocal.getMt().get().put("a","BBBB");
                System.out.println(Thread.currentThread().getName()+":"+TestThreadLocal.getMt().get().get("a")+":"+TestThreadLocal.getUserName());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"THREAD1").start();

        new Thread(()->{
            while (true){
                System.out.println(Thread.currentThread().getName()+":"+TestThreadLocal.getMt().get().get("a")+":"+TestThreadLocal.getUserName());
                TestThreadLocal.setUserName("AAAAA");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"THREAD2").start();
    }
}
